package cn.com.basic.framework.aliyun.oss.download;

import cn.com.basic.framework.aliyun.oss.OSSManager;
import cn.hutool.core.lang.Assert;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.ObjectMetadata;

import java.io.File;

/**
 * @author zhuxj
 */
public class FileDownloader extends Downloader {
    public FileDownloader(OSSManager ossManager) {
        super(ossManager);
    }

    public ObjectMetadata download(String localFile, String bucketName, String objectName) {
        Assert.isTrue(this.ossManager.getOss() != null, "oss client cannot be null");

        // 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖，不存在则新建。
        return this.ossManager.getOss().getObject(new GetObjectRequest(bucketName, objectName), new File(localFile));
    }
}
